//
//  EmoticonsCell.swift
//  emoticon模块代码
//
//  Created by rong on 15/7/8.
//  Copyright © 2015年 rong. All rights reserved.
//

import UIKit

class EmoticonsCell: UICollectionViewCell {
    
    private lazy var emoticonBtn = UIButton()
    
    var emoticon: Emoticon? {
        didSet {
            //设置cell里面的图片
            if let path = emoticon?.imgPath {
                emoticonBtn.setImage(UIImage(contentsOfFile: path), forState: UIControlState.Normal)
            } else {
                
                //？？？防止 cell的重用
                emoticonBtn.setImage(nil, forState: UIControlState.Normal)
            }
            
            // cell  的重用问题，好几个表情在一个cell里面
           // if emoticon?.emoji != nil {
                emoticonBtn.setTitle(emoticon?.emoji ?? "", forState: UIControlState.Normal)
            //}
            
            if emoticon?.isRemoveBtnFlag == true {
                emoticonBtn.setImage(UIImage(named: "compose_emotion_delete"), forState: UIControlState.Normal)
                emoticonBtn.setImage(UIImage(named: "compose_emotion_delete_highlighted"), forState: UIControlState.Normal)
            }
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        addSubview(emoticonBtn)
        emoticonBtn.frame = CGRectInset(bounds, 4, 4)
        emoticonBtn.backgroundColor = UIColor.whiteColor()
        emoticonBtn.userInteractionEnabled = false
    }

    required init(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
   
    
}
